<?php
require_once("admin_header.php");
?>

<?php
$description0="";
$description1="";
if (isset($_POST['syear']))
{
	require_once("../include/check_post_key.php");
	
	$contest_0_start=intval($_POST['syear'])."-".intval($_POST['smonth'])."-".intval($_POST['sday'])." ".intval($_POST['shour']).":".intval($_POST['sminute']).":00";
	$contest_0_end=intval($_POST['eyear'])."-".intval($_POST['emonth'])."-".intval($_POST['eday'])." ".intval($_POST['ehour']).":".intval($_POST['eminute']).":00";
	$contest_1_start=intval($_POST['SRyear'])."-".intval($_POST['SRmonth'])."-".intval($_POST['SRday'])." ".intval($_POST['SRhour']).":".intval($_POST['SRminute']).":00";
	$contest_1_end=intval($_POST['ERyear'])."-".intval($_POST['ERmonth'])."-".intval($_POST['ERday'])." ".intval($_POST['ERhour']).":".intval($_POST['ERminute']).":00";
//	echo $starttime;
//	echo $endtime;
	$contest_0_active=$_POST['checkcontest0'] == 1 ? 'Y' : 'N';
	$contest_1_active=$_POST['checkcontest1'] == 1 ? 'Y' : 'N';
	$title=$_POST['title'];
	$description0=$_POST['description0'];
	$description1=$_POST['description1'];
/*	if (get_magic_quotes_gpc ())
	{
		$title = stripslashes ($title);
		$description = stripslashes ($description);
	}*/
	$title=mysql_real_escape_string($title);
	$description=mysql_real_escape_string($description);
	$sql="INSERT INTO `cr_contest`(`contest_title`,`contest_0_start`,`contest_0_end`,`contest_1_start`,`contest_1_end`,`contest_0_active`,`contest_1_active`,`contest_0_description`,`contest_1_description`)
		VALUES('$title','$contest_0_start','$contest_0_end','$contest_1_start','$contest_1_end','$contest_0_active','$contest_1_active','$description0','$description1')";
//	echo $sql;
	mysql_query($sql) or die(mysql_error());
	$cid=mysql_insert_id();
	echo "添加比赛 ".$cid;
	$_SESSION["m$cid"]=true;
	
	$xm_kind=trim($_POST['xm_kind']);
	if($contest_1_active == 'Y' && strlen($xm_kind) == 0)
	{
		echo "<script language='javascript'>\n";
		echo "alert('<?php echo $rj_name; ?>可选项目不能为空!');\n";
		echo "history.go(-1);\n";
		echo "</script>";
		exit(0);
	}
	$pieces = explode(",",$xm_kind );
	if (count($pieces)>0 && strlen($pieces[0])>0){
		$sql_1="INSERT INTO `cr_xmkind`(`xmkind_name`,`contest_id`, `xmkind_num`) 
			VALUES ('$pieces[0]','$cid',1)";
		for ($i=1;$i<count($pieces);$i++){
			$sql_1=$sql_1.",('$pieces[$i]','$cid',$i+1)";
		}
		//echo $sql_1;
		mysql_query($sql_1) or die(mysql_error());
	}
	
	
	
	echo "<script>window.location.href=\"contest_list.php\";</script>";
}
else
{
	if(isset($_GET['cid']))
	{
		$cid=intval($_GET['cid']);
		$sql="select * from cr_contest WHERE `contest_id`='$cid'";
		$result=mysql_query($sql) or die(mysql_error());
		$row=mysql_fetch_object($result);
		$title=$row->contest_title;
		mysql_free_result($result);
	}
	include_once("../fckeditor/fckeditor.php") ;
?>

      <div class="fr wid59">
        <h2 class="h2">添加一场比赛</h2>
        <div class="middle">
<form method=POST >
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="40" align="left"><strong>包含赛事:
      </strong>
      <input value=1 checked="checked" type="checkbox" name="checkcontest0" />
<?php echo $sf_name; ?>
<input value=1 checked="checked" type="checkbox" name="checkcontest1" />
<?php echo $rj_name; ?> </td>
  </tr>
  <tr>
    <td height="40" align="left"><p align="left"><strong>标题:</strong>
          <input name="title" class="inpus1" size="71" value="<?php echo isset($title)?$title:""?>"/>
    </p></td>
  </tr>
  <tr>
    <td height="40" align="left"><strong><?php echo $sf_name; ?>开始注册时间:</strong></td>
  </tr>
  <tr>
    <td height="40" align="left"> 年:
      <input name="syear" class="inpus3" size="4" value=<?php echo date('Y');?> />
月:
<input name="smonth" class="inpus3" size="2" value=<?php echo date('m');?> />
日:
<input name="sday" class="inpus3" size="2" value=<?php echo date('d');?> />
时:
<input name="shour" class="inpus3" size="2" value=<?php echo date('H');?> />
分:
<input name="sminute" class="inpus3" value="00" size="2" /></td>
  </tr>
  <tr>
    <td height="40" align="left"><strong><?php echo $sf_name; ?>结束注册时间:</strong></td>
  </tr>
  <tr>
    <td height="40" align="left">年:
      <input name="eyear" class="inpus3" size="4" value=<?php echo date('Y');?> />
月:
<input name="emonth" class="inpus3" size="2" value=<?php echo date('m');?> />
日:
<input name="eday" class="inpus3" size="2" value=<?php echo date('d');?> />
时:
<input name="ehour" class="inpus3" size="2" value=<?php echo (date('H')+4)%24;?> />
分:
<input name="eminute" class="inpus3" value="00" size="2" /></td>
<?php require_once("../include/set_post_key.php");?>
  </tr>
  <tr>
    <td height="40" align="left"><strong><?php echo $sf_name; ?>说明:</strong>
    <?php
	$fck_description = new FCKeditor('description0') ;
	$fck_description->BasePath = '../fckeditor/' ;
	$fck_description->Height = 300 ;
	$fck_description->Width=600;
	$fck_description->Value = $description0;
	$fck_description->Create() ;
	?>
    </td>
  </tr>
 	
	<!-- 
  <tr>
    <td height="40" align="left"><textarea name="textarea" cols="45" rows="5" class="inpus4" id="textarea"></textarea></td>
  </tr>
     -->
  <tr>
    <td height="40" align="left"><strong><?php echo $rj_name; ?>开始注册时间:</strong></td>
  </tr>
  <tr>
    <td height="40" align="left">年:
      <input name="SRyear" class="inpus3" size="4" value=<?php echo date('Y');?> />
月:
<input name="SRmonth" class="inpus3" size="2" value=<?php echo date('m');?> />
日:
<input name="SRday" class="inpus3" size="2" value=<?php echo date('d');?> />
时:
<input name="SRhour" class="inpus3" size="2" value=<?php echo date('H');?> />
分:
<input name="SRminute" class="inpus3" value="00" size="2" /></td>
  </tr>
  <tr>
    <td height="40" align="left"><strong><?php echo $rj_name; ?>结束注册时间:</strong></td>
  </tr>
  <tr>
    <td height="40" align="left">年:
      <input name="ERyear" class="inpus3" size="4" value=<?php echo date('Y');?> />
月:
<input name="ERmonth" class="inpus3" size="2" value=<?php echo date('m');?> />
日:
<input name="ERday" class="inpus3" size="2" value=<?php echo date('d');?> />
时:
<input name="ERhour" class="inpus3" size="2" value=<?php echo (date('H')+4)%24;?> />
分:
<input name="ERminute" class="inpus3" value="00" size="2" /></td>
	<?php require_once("../include/set_post_key.php");?>
  </tr>
  <tr>
    <td height="40" align="left"><strong><?php echo $rj_name; ?>项目（英文字体的&quot;,&quot;隔开，比如“项目1,项目2,项目3”）:</strong></td>
  </tr>
  <tr>
    <td height="40" align="left"><input name="xm_kind" class="inpus1" size="71" /></td>
  </tr>
  <tr>
    <td height="40" align="left"><strong><?php echo $rj_name; ?>说明:</strong>
    <?php
	$fck_description = new FCKeditor('description1') ;
	$fck_description->BasePath = '../fckeditor/' ;
	$fck_description->Height = 300 ;
	$fck_description->Width=600;
	$fck_description->Value = $description0;
	$fck_description->Create() ;
	?>
	</td>
  </tr>
  	
	<!-- 
  <tr>
    <td height="40" align="left"><textarea name="textarea2" cols="45" rows="5" class="inpus4" id="textarea2"></textarea></td>
  </tr>
  	 -->
  <tr>
    <td height="40" align="left">
    <input type="image" name="submit" id="submit" src="<?php echo "../template/$BM_TEMPLATE/images/"; ?>02_03-16.jpg"/>
    <input type="image" name="reset" id="reset" src="<?php echo "../template/$BM_TEMPLATE/images/"; ?>06_03.jpg" onclick="this.form.reset(); return false;" /></td>
  </tr>
  <tr>
    <td height="40" align="left">&nbsp;</td>
  </tr>
  <tr>
    <td height="40" align="left">&nbsp;</td>
  </tr>
  <tr>
    <td height="40" align="left">&nbsp;</td>
  </tr>
</table>
</form>
        </div>
  </div>
     
<?php require_once("menu.php");


}
require_once("./admin_footer.php");

?>

